<template>
	<view class="main">
		<!-- <view class="my-header">
			<view class="header-lst dis-row v-box">
				<view class="header-span">个人中心</view>
				<view class="header-switch dis-row" @click="SwitchNnterprises">
					<view class="switch-img"><image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/my/swap.png"></image></view>
					<label>切换企业</label>
				</view>
			</view>
		</view> -->
		<view class="v-tops">
			<u-navbar :is-back="false" :safeAreaInsetTop="true" :placeholder="true">
				<view slot="left" class="header-span">个人中心</view>
				<view slot="right" class="header-switch dis-row" @click="SwitchNnterprises">
					<block v-if="userinfo.enIdentity==0">
						<view class="switch-img">
							<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/my/swap.png"></image>
						</view>
						<label>切换企业</label>
					</block>
					<block v-if="userinfo.enIdentity!=0">
						<view class="switch-img">
							<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/my/swap.png"></image>
						</view>
						<label>切换个人</label>
					</block>
				</view>
			</u-navbar>
		</view>
		<!--用户信息-->
		<view class="header-user">
			<view class="user-info v-box dis-row poser">
				<view class="user-face">
					<image
						:src="userinfo.avatar?userinfo.avatar:'https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/default-avatar.png'">
					</image>
				</view>
				<view class="user-text dis-clm">
					<view class="usertext-one dis-row">
						<text>{{userinfo.nickName?userinfo.nickName:'先生'}}</text>
						<block v-if="userinfo.isRealName">
							<view class="usertext-ico">
								<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/my/userico.svg"></image>
							</view>
							<label>实名认证</label>
						</block>
						<block v-if="userinfo.isEnterprise && userinfo.isEnterprise  ==1">
							<view class="usertext-ico">
								<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/comp-real.svg"></image>
							</view>
							<label>企业认证</label>
						</block>

					</view>
					<view class="usertext-two dis-row">
						<view class="usertexttwo-img"
							v-if="(userinfo.enIdentity == 0&&userinfo.vipRemainingTime>0)||(userinfo.enIdentity != 0&&userinfo.enterpriseVipRemainTime>0)">
							VIP
						</view>
						<label>{{userinfo.mobile}}</label>
					</view>
				</view>

				<view class="ercode" @click="getqrcode"
					style="display: flex;flex-direction: row;width: 120rpx;align-items: center;justify-content: center;position: absolute;right: 100rpx;padding-top: 63rpx;top: 0;">
					<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/my/ewm-svg.svg"
						style="width: 32rpx; height: 32rpx;" mode=""></image>
					<text style="font-size: 24rpx; margin-left: 10rpx;">推广</text>
				</view>
				<view class="usertext-sect dis-row" @click="editUserInfo">
					<view class="usertexttwo-secico">
						<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/my/useredit.svg"></image>
					</view>
					<label>修改</label>
				</view>
			</view>
		</view>
		<!-- 二维码 -->
		<u-popup :show="showqrcode" :round="10" mode="center" closeable="true" @close="offqrcode"
			closeOnClickOverlay="true" customStyle="overflow: hidden;" safe-area-inset-bottom="false">
			<view class="qrcodeimg">
				<image :src="bufferImg" mode="" style="width: 100%; height: 100%;" :show-menu-by-longpress="true">
				</image>
			</view>
			<view class="" style="margin: 20rpx auto; font-size: 30rpx;">
				长按二维码保存至相册
			</view>
		</u-popup>
		<u-overlay :show="showuploadImage">
			<view class="autloading"
				style="width: 100%;height: 100%;display: flex;justify-content: center;align-items: center;">
				<u-loading-icon :show="showuploadImage" color="white"></u-loading-icon>
			</view>

		</u-overlay>
		<!--提醒框-->
		<view class="user-warn poser"
			v-if="(userinfo.enIdentity == 0&&userinfo.vipRemainingTime <8 && userinfo.vipRemainingTime>0)||(userinfo.enIdentity != 0&&userinfo.enterpriseVipRemainTime<8 && userinfo.enterpriseVipRemainTime>0)">
			<view class="diamond"></view>
			<view class="userwarn-info">
				<view v-if="userinfo.enIdentity == 0&&userinfo.vipRemainingTime <8 && userinfo.vipRemainingTime>0"
					class="userwarn-text">vip使用日期还剩<label>{{userinfo.vipRemainingTime}}</label>天</view>
				<view
					v-if="userinfo.enIdentity != 0&&userinfo.enterpriseVipRemainTime <8 && userinfo.enterpriseVipRemainTime>0"
					class="userwarn-text">企业vip使用日期还剩<label>{{userinfo.enterpriseVipRemainTime}}</label>天</view>
			</view>
			<view class="userwarn-click" @click="getCentimeter">去续费</view>
		</view>
		<!--分类栏目-->
		<!-- <view class="user-class dis-row">
			<view class="user-childclass dis-clm" @click="getCentimeter">
				<label>{{userinfo.workPoint?userinfo.workPoint:0}}</label>
				<text>工分</text>
			</view>
			<view class="user-childclass dis-clm" @click="NavUrlRd('/pagesC/my/BeInterested')">
				<label>{{userinfo.interestedIn?userinfo.interestedIn:0}}</label>
				<text>感兴趣</text>
			</view>
			<view class="user-childclass dis-clm" @click="NavUrlRd('/pagesC/my/follow')">
				<label>{{userinfo.followNum?userinfo.followNum:0}}</label>
				<text>关注</text>
			</view>
			<view class="user-childclass dis-clm" @click="NavUrlRd('/pagesC/my/browse')">
				<label>{{userinfo.viewNum?userinfo.viewNum:0}}</label>
				<text>浏览</text>
			</view>
			<view class="user-childclass dis-clm" @click="NavUrlRd('/pagesC/my/contacts')">
				<label>{{userinfo.cardNum?userinfo.cardNum:0}}</label>
				<text>名片夹</text>
			</view>
		</view> -->
		<!--名片和招工管理-->
		<block v-if="userinfo.enIdentity&&userinfo.enIdentity != 0">
			<view class="qiyeblock" @click="NavUrlRd('/pagesC/my/RecruitmentManagement?entId='+userinfo.enIdentity)">
				<view class="lineout v-box poser dis-clm">
					<view class="qyblock-name">招工管理</view>
					<!-- <view class="sendzg dis-row" @click="NavUrlRd('/pagesC/release/index')">
						<label>
							<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/user-add.svg"></image>
						</label>
						<text>发布招工</text>
					</view> -->
					<view class="qynums">在线招工数<label>{{userinfo.orderNumber}}</label></view>
					<view class="qytext">您有{{userinfo.orderNumber}}个招工待处理，去处理</view>
					<view class="dis-row" style="margin-top: 20rpx;">
						<u-icon name="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/comp-real.svg" size="40rpx"
							:label="userinfo.enterpriseName" labelColor="#ffffff"></u-icon>
					</view>
					<!-- <view class="qiyeclass dis-row">
						<view class="classsmall dis-row" @click="NavUrlRd('/pagesC/my/RecruitmentManagement')">
							<label>
								<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/refresh.png"></image>
							</label>
							<text>刷新招工</text>
						</view>
						<view class="classsmall dis-row" @click="NavUrlRd('/pagesC/my/RecruitmentManagement')">
							<label>
								<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/setTop.png"></image>
							</label>
							<text>置顶招工</text>
						</view>
					</view> -->
				</view>
			</view>
		</block>
		<!-- <block v-else> -->
		<block>
			<view class="block-sec v-box dis-row" v-if="userinfo.enIdentity==0">
				<view class="blocksec-first dis-clm" v-if="userinfo.isPublish==1" @click="editUserMP">
					<label>我的名片</label>
					<text>免费发布，更多好活在等你</text>
				</view>
				<view class="blocksec-first dis-clm" v-if="userinfo.isPublish!=1"
					@click="gocard('/pagesB/releaseWork/index')">
					<label>名片发布</label>
					<text>免费发布，更多好活在等你</text>
				</view>
				<view class="blocksec-sect dis-clm" @click="NavUrlRd('/pagesC/my/RecruitmentManagement')">
					<label>招工管理</label>
					<text>管理已发布的招工信息</text>
				</view>
			</view>
			<view v-else style="height: 20rpx;"></view>
		</block>

		<!--我的服务-->
		<view class="myserver-h3">我的服务</view>
		<view class="myserver-list">
			<view class="ser-item dis-clm" @click="NavUrlRd('/pagesC/my/getCentimeter')">
				<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/my/ico-gf.svg"></image>
				<text>获取工分</text>
			</view>
			<view class="ser-item dis-clm" @click="shareManage">
				<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/my/ico-jifen.svg"></image>
				<text>推广管理</text>
			</view>
			<!-- <view class="ser-item dis-clm" click="userWork">
					<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/my/ico-jifen.svg"></image>
					<text>推广管理</text>
			</view> -->
			<view class="ser-item dis-clm" @click="realNameurl">
				<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/my/ico-smrz1.svg"></image>
				<text>实名认证</text>
			</view>
			<view class="ser-item dis-clm" @click="NavUrlRd('/pagesC/my/EnterpriseCertification')">
				<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/my/ico-qyrz.svg"></image>
				<text>企业认证</text>
			</view>
			<!-- <view class="ser-item dis-clm">
				<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/my/ico-yule.svg"></image>
				<text>我的娱乐</text>
			</view> -->
			<view class="ser-item dis-clm" @click="lianxikefu">
				<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/my/ico-kefu.svg"></image>
				<text>联系客服</text>
			</view>
			<!-- <view class="ser-item dis-clm" @click="navNewsInfo">
				<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/my/ico-zixun.svg"></image>
				<text>平台资讯</text>
			</view> -->
			<view class="ser-item dis-clm" @click="NavUrlRd('/pagesC/my/browse')">
				<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/my/ico-dingyue.svg"></image>
				<text>我的浏览</text>
			</view>
			<view class="ser-item dis-clm" @click="navcompy">
				<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/my/enterprise.svg"></image>
				<text>入驻企业</text>
			</view>
			<view class="ser-item dis-clm" @click="navtovip">
				<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/my/vip-line.svg"></image>
				<text>会员充值</text>
			</view>
		</view>
		<view class="myserver-h3">设置与帮助</view>
		<view class="myserver-list">
			<view class="ser-item dis-clm" @click="NavUrlRd('../../pagesC/my/systemSet')">
				<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/my/ico-set.svg"></image>
				<text>系统设置</text>
			</view>
			<view class="ser-item dis-clm" @click="fankuiClick('../../pagesC/newsinfo/helps')">
				<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/my/ico-help.svg"></image>
				<text>帮助与反馈</text>
			</view>
			<view v-if="userinfo.id == 5369" class="ser-item dis-clm" @click="NavUrlRd('/pages/getopengid/getopengid')">
				<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/my/ico-help.svg"></image>
				<text>获取群id</text>
			</view>
			<view v-if="userinfo.id == 5369" class="ser-item dis-clm" @click="NavUrlRd('/pages/prizeDraw/prizeDraw')">
				<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/my/ico-help.svg"></image>
				<text>抽奖</text>
			</view>
		</view>
		<!--底部菜单-->


		<u-popup :show="iscomshow" :closeable="true" :round="20" @close="showcose">
			<view class="nodets">
				<view class="noideName">{{(userinfo.isRealName&&userinfo.isRealName==1)?'切换企业':'切换个人'}}</view>
				<view class="nodeList">
					<view v-for="(nvitem,nvindex) in Nnterprises" :key="nvindex"
						:class="{'nvactive':currindex == nvindex}" @click="checkItem(nvitem,nvindex)">
						{{nvitem.itemName}}
					</view>
				</view>
				<view class="addres-footer dis-row">
					<view class="addres-btn" @click="clearSaixuan">清除</view>
					<view class="addres-btn" @click="getChecksaixuan">确定选择</view>
				</view>
			</view>
		</u-popup>
		<uTabbar :value="3"></uTabbar>
	</view>
</template>

<script>
	import uTabbar from "@/components/uTabbar/uTabbar.vue";
	import Index from "@/common/index-model.js"
	let index = new Index();
	let that = null;
	export default {
		data() {
			return {
				iscomshow: false,
				userinfo: {},
				Nnterprises: [], //可切换的企业
				currindex: -1,
				showqrcode: false,
				bufferImg: '', // 存储二维码的 URL
				showuploadImage: false
			}
		},
		components: {
			uTabbar
		},
		// onPullDownRefresh() {
		// 	setTimeout(function () {
		// 		uni.stopPullDownRefresh();
		// 	}, 1000);
		// },
		onShareAppMessage(res) {
			if (res.from === 'button') { // 来自页面内分享按钮
			}
			return {
				title: '找活干、招工人，就用天下工人',
				path: '/pages/user/index?userid=' + uni.getStorageSync('userid'),
				imageUrl: 'https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20230327160119.png'
			}
		},
		onShareTimeline(res) {
			return {
				title: '找活干、招工人，就用天下工人',
				query: '/pages/user/index?userid=' + uni.getStorageSync('userid'),
				imageUrl: 'https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20230327160119.png'
			}
		},
		methods: {
			offqrcode() {
				this.showqrcode = false
			},
			//生成分享码
			getqrcode() {
				this.showuploadImage = true
				index.getPublicUserMember({
					path: 'pages/user/index',
					code: uni.getStorageSync('userid')
				}, "/client/share/wxQrcode", 'get', res => {
					if (res.data.code == 200) {
						console.log(res.data.result)
						this.bufferImg = res.data.result
						this.showqrcode = true
						this.showuploadImage = false
					} else {
						if (uni.getStorageSync('userid') == '') {
							index.show_tips('请先登录')
						} else {
							index.show_tips('二维码请求失败')
						}


						this.showuploadImage = false
					}
				})

			},
			userWork() {
				console.log('----99999911111999999----')
				if (this.userinfo.nickName) {
					this.NavUrlRd('/pagesC/my/Mybusinesscard')
				} else {
					this.NavUrlRd('/pagesC/my/MyEditUserInfo')
				}
			},
			shareManage() {
				// index.navigate_to('/pagesC/my/Mybusinesscard');
				// index.navigate_to('../../pagesC/my/Mybusinesscard')
				console.log('----99999999999999999999----')
				this.NavUrlRd('/pagesC/my/ShareManage?userid=' + this.userinfo.id)
			},
			lianxikefu() {
				uni.makePhoneCall({
					phoneNumber: "19528818989"
				});
			},
			//跳转到平台资讯
			navNewsInfo() {
				index.navigate_to('../../pagesC/newsinfo/index')
			},
			//跳转到已认证企业列表
			navcompy() {
				index.navigate_to('../../pagesC/compy/index')
			},
			checkItem(item, index) {
				this.currindex = index
				this.setNnterprises(item)
			},
			clearSaixuan() {
				this.currindex = -1
				this.iscomshow = false
			},
			getChecksaixuan() {
				if (this.currindex == -1) {
					index.show_tips('请选择要切换的企业')
					return false
				}
				this.setNnterprises(this.Nnterprises[this.currindex])
			},
			setNnterprises(item) {
				let url = 'client/individual/switchIdentity/' + item.itemId
				index.getPublicUserMember({}, url, 'post', res => {
					if (res.data.code == 200 && res.data.success) {
						index.show_tips('切换成功')
						this.iscomshow = false
						setTimeout(() => {
							this.getUserInfo()
						}, 400)
					} else {
						index.show_tips(res.data.message)
						return false
					}
				})
			},
			SwitchNnterprises() {
				this.iscomshow = true
			},
			getSwitchNnterprises() {
				index.getPublicUserMember({}, 'client/individual/switchIdentityList', 'get', res => {
					if (res.data.code == 200 && res.data.success) {
						this.Nnterprises = res.data.result
						this.currindex=this.Nnterprises.findIndex(s => s.itemId == this.userinfo.enIdentity)
					}
				})
			},
			showcose() {
				this.iscomshow = false
			},
			getUserInfo() {
				index.getPublicUserMember({}, '/client/individual/homePage', 'get', res => {
					if (res.data.code == 200 && res.data.success) {
						this.userinfo = res.data.result;
						this.getSwitchNnterprises()
						if (res.data.result.mobile.charAt(0) == 9) {
							this.userinfo.mobile = '';
						}
					} else if (res.data.code == '401') {
						uni.removeStorageSync('');
						index.navigate_to('../../pagesC/login/login');
					} else {
						index.show_tips(res.data.message);
						return false
					}
				})

			},
			getCentimeter() {
				// index.navigate_to('/pagesC/my/getCentimeter')
				// this.NavUrlRd('/pagesC/my/getCentimeter')
				let uid = uni.getStorageSync('userid')
				this.NavUrlRd('/pagesB/rechargeVip/rechargeVip?userId='+uid + '&&entid=' + this.userinfo.enIdentity)
				
			},
			editPhone() {
				// index.navigate_to('/pagesC/my/MyEditPhone')
				this.NavUrlRd('/pagesC/my/MyEditPhone')
			},
			editUserInfo() {
				// index.navigate_to('/pagesC/my/MyEditUserInfo')
				let uid = uni.getStorageSync('userid')
				console.log('当前登录的用户id是', this.uid)
				this.NavUrlRd('/pagesC/my/MyEditUserInfo?type=1&userId=' + uid)
			},
			navtovip(){
				let uid = uni.getStorageSync('userid')
					this.NavUrlRd('/pagesB/rechargeVip/rechargeVip?userId='+uid + '&&entid=' + this.userinfo.enIdentity)
				},
			editUserMP(){
				let uid = uni.getStorageSync('userid')
				console.log('当前登录的用户id是111', uid)
				this.NavUrlRd('/pagesC/my/MyEditUserInfo?type=2&userId='+uid)
			},
			//通用跳转
			NavUrlRd(url) {
				if (uni.getStorageSync('token')) {
					index.navigate_to(url)
				} else {
					uni.navigateTo({
						url: "/pagesC/login/login"
					});
				}
			},
			gocard(url) {
				if (this.userinfo.nickName) {
					this.NavUrlRd(url)
				} else {
					let uid = uni.getStorageSync('userid')
					this.NavUrlRd('/pagesC/my/MyEditUserInfo?type=1&userId=' + uid)
				}
			},
			add(value) {
				//console.log(value,'====ffff====')
				index.show_tips('我师傅级的 ')
			},
			//实名认证
			realNameurl() {
				let url = "../../pagesC/my/RealName"
				// index.navigate_to(url)
				this.NavUrlRd(url)
				// if(this.userinfo.isRealName && this.userinfo.isRealName==1){
				// 	index.show_tips('您已经完成实名认证了')
				// 	return false
				// }else{
				// 	index.navigate_to(url)
				// }
			},
			isLogin(url) {

				if (uni.getStorageSync('token')) {
					uni.switchTab({
						url: "/pages/user/index"
					});
				} else {
					uni.navigateTo({
						url: "/pagesC/login/login"
					});
				}
			},
			fankuiClick(url) {
				uni.navigateTo({
					url: url
				})
			}
		},
		onLoad(opt) {
			console.log('分享给你的用户->', opt)
			// let inviteUserId = opt.scene
			// if(inviteUserId){
			// 	inviteUserId = decodeURIComponent(inviteUserId);
			// 	inviteUserId = index.UrlParamHash(inviteUserId);
			// 	uni.setStorageSync('shareUserId', opt.scene);
			// 	console.log("改变了邀请id",opt.scene)
			// 	uni.setStorageSync('inviteUserId', opt.scene);
			// }
			let q = opt.q;
			if (q) {

				q = decodeURIComponent(q);
				q = index.UrlParamHash(q);
				console.log(q.scene, 'q.scene')
				console.log(q.userid, 'q.userid')
				if (q.userid) {
					uni.setStorageSync('shareUserId', q.userid);
				}
				if (q.scene) {
					uni.setStorageSync('shareUserId', q.scene);
				}
			} else {
				console.log(opt.scene, 'opt.scene')
				console.log(opt.userid, 'opt.userid')
				if (opt.userid) {
					uni.setStorageSync('shareUserId', opt.userid);
				}
				if (opt.scene) {
					uni.setStorageSync('shareUserId', opt.scene);
				}
			}
			uni.hideTabBar();

			if (uni.getStorageSync('token')) {
				this.getUserInfo()
				// this.getSwitchNnterprises()
			}
		},
		onShow() {
			if (uni.getStorageSync('token')) {
				this.getUserInfo()
				// this.getSwitchNnterprises()
			}
		}
	}
</script>

<style lang="scss">
	@import url("@/static/css/publics.css");
	@import url("@/static/css/my.css");

	::v-deep {
		.u-navbar--fixed {
			background-size: 100%;
			// background-image: url('https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/bg1.png');
			// background-repeat: no-repeat;
			background: none;

			// background-image: linear-gradient(to bottom, #42cdff, #0288ff);
			&>view {
				background: transparent !important;
			}

			.leftText {
				color: #fff;
				font-size: 36rpx;
				font-weight: bold;
			}
		}
	}

	.qrcodeimg {
		width: 500rpx;
		height: 550rpx;
		border-radius: 50rpx;
		margin-top: 80rpx;
		padding: 0 40rpx;
	}

	.share {
		padding: 0;
		font-size: 0rpx;
		color: #3D3D3D;
		background: none;
	}

	.share image {
		padding: 0;
		margin: 4rpx auto;
	}

	button[type=default] {
		background-color: #fff;
	}

	.share::after {
		border: none;
		background: none !important;
	}
</style>